package com.pro.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;
import com.pro.entity.BannerEntity;
import com.pro.util.DBManager;
import com.pro.util.QueryResult;

public class BannerDaoImpl {
	//查询轮播图
	public ArrayList<BannerEntity> bannerAll(){
		ArrayList<BannerEntity> alist= new ArrayList<BannerEntity>(); //集合
	    String sqlString="select id,banner_img,banner_title,create_time from banner";
	    //执行sql语句，并获取执行后的结果
	    QueryResult rSet=DBManager.executeQuery(sqlString);
	      if (rSet!=null) {
	        try {
	        	//处理结果
	          while (rSet.rs.next()) {
	        	  //接收到的数据按需处理
	            alist.add(new BannerEntity(rSet.rs.getInt("id"),
	            		rSet.rs.getString("banner_img"),
	            		rSet.rs.getString("banner_title"),
	            		rSet.rs.getString("create_time")));
	          }
	        } catch (SQLException e) {
	          e.printStackTrace();
	        }
	      }
	      rSet.close();
	    return alist;
	}
	//修改
	 public int bannerUpdate(BannerEntity bEntity) {
 		String sqlString="update banner set banner_img='"+bEntity.getBannerImg()+"',banner_title='"+bEntity.getBannerTitle()+"',create_time='"+bEntity.getCreateTime()+"' where id = '"+bEntity.getId()+"'";
 		 int result= DBManager.executeUpdate(sqlString);
 		return result;
 	}
	//添加
	 public int bannerAdd(BannerEntity bEntity) {
 		String sqlString="insert into banner(banner_img,banner_title,create_time) values('"+bEntity.getBannerImg()+"','"+bEntity.getBannerTitle()+"','"+bEntity.getCreateTime()+"')";
 		 int result= DBManager.executeUpdate(sqlString);
 		return result;
 	}
	 //删除
	 public int bannerDelete(int id) {
			// TODO Auto-generated method stub
			String sqlString = "delete from banner where id = '"+id+"'";
			int result = DBManager.executeUpdate(sqlString);
			return result;
		}
}
